package com.xiaoshou.action;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class A_CopyFileToTomcat {
	public static void main(String[] args) throws IOException {
		File file = new File("C:\\Users\\Administrator\\Desktop\\新添加的技术支持");//原技术支持 - 副本
		File[] fileList = file.listFiles();
		for (File file2 : fileList) {
			if(file2.isFile()){
				copyFiles(file2);
			}else if(file2.isDirectory()){
				File[] ff = file2.listFiles();
				for (File file3 : ff) {
					if(file3.isFile()){
						copyFiles(file3);
					}else if(file3.isDirectory()){
						System.out.println("文件夹不用拷了，有相应压缩的。");
					}
				}
			}
		}
	}
	public static void copyFiles(File file) throws IOException{
		File sourceFile = new File(file.getPath());

		File newFile = new File("E:\\apache-tomcat-7.0.25\\webapps\\xiaoshou\\files\\"+sourceFile.getName());
		if (!newFile.exists()) {
			newFile.createNewFile();
			// 读取
			FileInputStream inputStream = new FileInputStream(sourceFile);
			BufferedInputStream bufferedInputStream = new BufferedInputStream(
					inputStream);

			// 写
			FileOutputStream outputStream = new FileOutputStream(newFile);
			BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(
					outputStream);

			int b = 0;
			byte[] buffer = new byte[2048];

			long startTime = System.currentTimeMillis();
			while (b != -1) {
				b = bufferedInputStream.read(buffer);
				bufferedOutputStream.write(buffer, 0, buffer.length);
			}
			System.out.println(sourceFile.getPath()+"耗时：" + (System.currentTimeMillis() - startTime)
					+ "ms");

			bufferedInputStream.close();

			bufferedOutputStream.flush();
			bufferedOutputStream.close();
		}else {
			System.out.println("已经存在\t"+newFile.getPath());
		}

		
	}

}
